package com.work.service.impl;


import com.work.annotation.Autowired;
import com.work.annotation.Service;
import com.work.annotation.Transactional;
import com.work.dao.AccountDao;
import com.work.pojo.Account;
import com.work.service.TransferService;

/**
 * @program: transfer
 * @description
 * @author: luffy
 * @create: 2020-06-30 15:31
 */
@Service
public class TransferServiceImpl implements TransferService {

    /**
     * 构造函数传值
     * set方法传值
     */
    @Autowired
    private AccountDao accountDao;


    @Transactional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            //int i = i/0;
            from.setMoney(from.getMoney() - money);
            to.setMoney(to.getMoney() + money);
            accountDao.updateAccountByCardNo(from);
            accountDao.updateAccountByCardNo(to);
    }

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public AccountDao getAccountDao() {
        return accountDao;
    }
}
